package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.Order;
import com.example.demo.entity.ParkingLot;
import com.example.demo.entity.Vehicle;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {


//    @Results({
//            @Result(column = "id",property = "id"),
//            @Result(column = "pricing_standard_id",property = "pricingStandard",one =@One(select = "com.example.demo.mapper.PricingStandardMapper.selectById")),
//            @Result(column = "pricing_lot_id",property = "pricingLot",one =@One(select = "com.example.demo.mapper.PricingLotMapper.getById")),
//            @Result(column = "vehicle_id",property = "vehicle",one =@One(select = "com.example.demo.mapper.PricingStandardMapper.getById"))
//    })
    @Select("select * from orders join parking_lot " +
            "on orders.parking_lot_id=parking_lot.id" +
            " join pricing_standard on pricing_standard.id=parking_lot.pricing_standard_id" +
            " join vehicle on orders.vehicle_id=vehicle.id")
    List<Order> getAll();



    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "pricing_standard_id",property = "pricingStandard",one =@One(select = "com.example.demo.mapper.PricingStandardMapper.selectById")),
            @Result(column = "parking_lot_id",property = "parkingLot",one =@One(select = "com.example.demo.mapper.ParkingLotMapper.getById")),
            @Result(column = "vehicle_id",property = "vehicle",one =@One(select = "com.example.demo.mapper.VehicleMapper.getById"))
    })
    @Select("select * from orders " +
            " join parking_lot on orders.parking_lot_id=parking_lot.id" +
            " join pricing_standard on pricing_standard.id=parking_lot.pricing_standard_id" +
            " join vehicle on orders.vehicle_id=vehicle_id" +
            " where orders.id=#{id}")
    Order getById(Long id);

    @Insert("insert into orders set in_dateTime=#{inDateTime},out_DateTime=#{outDateTime}" +
            ",price=#{price},is_PayComplete=#{isPayComplete},is_RequireInvoicing=#{isRequireInvoicing}" +
            ",parking_lot_id=#{parkingLot.id}" +
            ",pricing_standard_id=#{pricingStandard.id}" +
            ",vehicle_id=#{vehicle.id}")
    int insert(Order entity);

    @Update("update orders set in_dateTime=#{inDateTime}" +
            ",out_DateTime=#{outDateTime}" +
            ",price=#{price}" +
            ",is_PayComplete=#{isPayComplete}" +
            ",is_RequireInvoicing=#{isRequireInvoicing}" +
            ",parking_lot_id=#{parkingLot.id}" +
            ",pricing_standard_id=#{pricingStandard.id}" +
            ",vehicle_id=#{vehicle.id}" +
            " where id=#{id}")
    int update(Order entity);



}
